<?php
	$link = mysql_connect("localhost", "admin", "Xurpas123");
	mysql_select_db("smsnic",$link);
	
	$result= mysql_query("SELECT cl.`nombres` , t.`telefono` , COUNT( * ) AS cantidad
FROM  `envios` e
INNER JOIN  `mensajes` m ON ( e.`id_mensaje` = m.`id` ) 
INNER JOIN  `telefonos` t ON ( e.`id_telefono` = t.`id` ) 
INNER JOIN cliente cl ON ( t.`telefono` LIKE CONCAT(  '505', cl.`telefono` ) ) 
INNER JOIN  `operadora` o ON ( t.`operadora_id` = o.`id` ) 
INNER JOIN estado esta ON ( e.`estado` = esta.`id` ) 
where  e.`estado`=1 and e.`fecha` > '".$fecha_ini."' and e.`fecha` < '".$fecha_fin."'
group by cl.`id`", $link) or die(mysql_error());
						
				$i=0;		
while ($row = mysql_fetch_assoc($result)) 
		{
			 $datos1[]= intval($row['cantidad']);
			 $datos2[]= "'".$row['nombres']."'";
			 
		}

?>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Highcharts Example</title>
		
		
		<!-- 1. Add these JavaScript inclusions in the head of your page -->

		<script type="text/javascript" src="../graficos/js/highcharts.js"></script>
		
		<!-- 1a) Optional: add a theme file -->
		<!--
			<script type="text/javascript" src="../js/themes/gray.js"></script>
		-->
		
		<!-- 1b) Optional: the exporting module -->
		<script type="text/javascript" src="../graficos/js/modules/exporting.js"></script>
		
		
		<!-- 2. Add the JavaScript to initialize the chart on document ready -->
		<script type="text/javascript">
		
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container',
						defaultSeriesType: 'column'
					},
					title: {
						text: 'Cantidad de SMS enviados a un cliente.'
					},
					subtitle: {
						text: '.'
					},
					xAxis: {
						categories: [
							<?php echo implode($datos2, ','); ?>
						]
					},
					yAxis: {
						min: 0,
						title: {
							text: 'Cantidad de mensajes (unidades)'
						}
					},
					legend: {
						layout: 'vertical',
						backgroundColor: '#FFFFFF',
						align: 'left',
						verticalAlign: 'top',
						x: 100,
						y: 70,
						floating: true,
						shadow: true
					},
					tooltip: {
						formatter: function() {
							return ''+
								this.x +': '+ this.y +' SMS';
						}
					},
					plotOptions: {
						column: {
							pointPadding: 0.2,
							borderWidth: 0
						}
					},
				        series: [{
						name: 'Clientes',
						data: [ <?php echo implode($datos1, ','); ?>]
				
					}]
				});
				
				
			});
				
		</script>
		
	</head>
	<body>
		
		<!-- 3. Add the container -->
		<div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
		
				
	</body>
</html>
